#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>

#define MAXUSED	16
static struct timeval tv_start[MAXUSED];
static struct timeval tv_end[MAXUSED];


void time_line_start(int idx)
{
	if(idx >= MAXUSED) {
		printf("the index is bigger than support!\n");
	}
	gettimeofday(&tv_start[idx], NULL);
}

void time_line_end(const char *name, int idx)
{
	struct timeval temp;

	if(idx >= MAXUSED) {
		printf("the index is bigger than support!\n");
	}
	gettimeofday(&tv_end[idx], NULL);

	temp.tv_sec = tv_end[idx].tv_sec - tv_start[idx].tv_sec;
	temp.tv_usec = temp.tv_sec * 1000000 + tv_end[idx].tv_usec - tv_start[idx].tv_usec;

	temp.tv_sec = temp.tv_usec / 1000000;
	temp.tv_usec = temp.tv_usec % 1000000;

	printf("%s->total time is %ds %dus\n", name, temp.tv_sec, temp.tv_usec);
}
